#include "to_be_continued_text.h"

TO_BE_CONTINUED_TEXT::TO_BE_CONTINUED_TEXT(CASH *cash):QObject(), QGraphicsItemGroup()
{

    this->setZValue(1);

    tl_anims = new QTimeLine(1000, this);

    item_to = new GRAPHICS_PIXMAP_ITEM(*cash->cash_pixmap->value("Res/text/to_be_continued/to.png"), this);
    item_be = new GRAPHICS_PIXMAP_ITEM(*cash->cash_pixmap->value("Res/text/to_be_continued/be.png"), this);
    item_continued = new GRAPHICS_PIXMAP_ITEM(*cash->cash_pixmap->value("Res/text/to_be_continued/continued.png"), this);
    item_dots = new GRAPHICS_PIXMAP_ITEM(*cash->cash_pixmap->value("Res/text/to_be_continued/dots.png"), this);

    anim_init();
}

TO_BE_CONTINUED_TEXT::~TO_BE_CONTINUED_TEXT(){}


QPainterPath TO_BE_CONTINUED_TEXT::shape() const
{
    return QPainterPath();
}

//func initialize animations
void TO_BE_CONTINUED_TEXT::anim_init()
{

//animations for item to
    QGraphicsItemAnimation *anim_to = new QGraphicsItemAnimation(this);
    anim_to->setItem(item_to);
    anim_to->setTimeLine(tl_anims);

    anim_to->setPosAt(1, QPointF(261, 330));
    anim_to->setPosAt(0, anim_to->posAt(1) - QPointF(7000, 0));

    item_to->setPos(QPointF(-2000, 0));

//animations for item be
    QGraphicsItemAnimation *anim_be = new QGraphicsItemAnimation(this);
    anim_be->setItem(item_be);
    anim_be->setTimeLine(tl_anims);

    anim_be->setPosAt(1, QPointF(404, 330));
    anim_be->setPosAt(0, anim_be->posAt(1) - QPointF(2000, 0));

    item_be->setPos(QPointF(-2000, 0));

//animations for item continued
    QGraphicsItemAnimation *anim_continued = new QGraphicsItemAnimation(this);
    anim_continued->setItem(item_continued);
    anim_continued->setTimeLine(tl_anims);

    anim_continued->setPosAt(1, QPointF(573, 330));
    anim_continued->setPosAt(0, anim_continued->posAt(1) + QPointF(3000, 0));

    item_continued->setPos(QPointF(-2000, 0));

//animations for item dots
    QGraphicsItemAnimation *anim_dots = new QGraphicsItemAnimation(this);
    anim_dots->setItem(item_dots);
    anim_dots->setTimeLine(tl_anims);

    anim_dots->setPosAt(1, QPointF(1116, 330));
    anim_dots->setPosAt(0, anim_dots->posAt(1) + QPointF(7000, 0));

    item_dots->setPos(QPointF(-2000, 0));

}

void TO_BE_CONTINUED_TEXT::anim_show()
{
    tl_anims->stop();
    tl_anims->setDirection(QTimeLine::Forward);
    tl_anims->start();
}

void TO_BE_CONTINUED_TEXT::anim_hide()
{
    tl_anims->stop();
    tl_anims->setDirection(QTimeLine::Backward);
    tl_anims->start();
}
